package com.jizi.machine;

import lombok.extern.slf4j.Slf4j;

import java.util.HashSet;
import java.util.Set;

import static com.jizi.machine.utils.XianyuSearchUtils.extracted;

/**
 * @author song1
 * @version 1.0.0
 * @since 2025/4/8
 */
@Slf4j
public class XianyuSearchTwo {

    public static void main(String[] args) throws Exception {
        String email = "2550635872@qq.com";
        //String email = "1678846945@qq.com";
        String apiString = "curl 'https://h5api.m.goofish.com/h5/mtop.taobao.idlemtopsearch.pc.search/1.0/?jsv=2.7.2&appKey=34839810&t=1744092191799&sign=f2f21783a6b4fc2bf61f87851a692954&v=1.0&type=originaljson&accountSite=xianyu&dataType=json&timeout=20000&api=mtop.taobao.idlemtopsearch.pc.search&sessionOption=AutoLoginOnly&spm_cnt=a21ybx.search.0.0&spm_pre=a21ybx.search.searchInput.0' \\\n" +
                "  -H 'accept: application/json' \\\n" +
                "  -H 'accept-language: zh-CN,zh;q=0.9' \\\n" +
                "  -H 'content-type: application/x-www-form-urlencoded' \\\n" +
                "  -b 'cna=2V0zH7A19CwCAbcGAhRt8JmE; t=f762d5a088003dff9fa7816381ceab2a; tracknick=tb529718957; isg=BJiYNIMoS502f2ZT7aADQbL-acYqgfwL1QJIaNKI9VORbTtXepClmw0OoaXdxrTj; xlly_s=1; unb=2761267121; havana_lgc2_77=eyJoaWQiOjI3NjEyNjcxMjEsInNnIjoiZDY3OTBjZjYyMmZiMDA5ZDFkYjE3ZDE4N2Q0NTVjZGUiLCJzaXRlIjo3NywidG9rZW4iOiIxSEVMVk5WeEFWWVhtWWpfc1FYMkhBdyJ9; _hvn_lgc_=77; havana_lgc_exp=1746597268193; _samesite_flag_=true; sgcookie=E100HdLeYARHhpP%2BlzvT%2FyBMhxdZv8wFU%2FblBinmzU6kuDyGPbdffBdVvB7GIXyoZJdKGNrp7sRjj1MbZxzVZSRMWGm3x1XEKEvVWH51QoHJPDc%3D; cookie2=2c6c05f77dcb1f1003bd936f4ebb4d63; csg=f822cab5; _tb_token_=38f7e3837a7ee; sdkSilent=1744162656726; mtop_partitioned_detect=1; _m_h5_tk=bf21b8c3f9265c8c218780e93b1b4c23_1744099826215; _m_h5_tk_enc=2791a849641f2a78ecc12113f8926df9; tfstk=gZ_jCbDIwxDXVVHli-FyOK6Y-rL1hOaE1fOOt13q6ELxBACpUtJ2u546BtvPuK52kd31Q17VQN1i5CCOISvaiu5ciFYTLJ8_8sf0bTQSfZt9e_Ck1AHY4nHUfEr8LJzUzohJ5-wF3pkd3zOMeId9XIFWyBA6WjdOBLKJ9BkvWFBTNLde1VdxkFL-wCJJBFLOB_FW_j8oOCZXnsNmjLaL_W81MLgtWZUMcpa6dQAPPVt6dsQjWVdMGn9dMLweudk921x1Sf06vsIhIBBxHR9GP_QAv9er0KIB16S1Mr3JuZfAvhQLIcBBlOtdk3GtlUf2FUORJ5oHUa9VBZt8T2twyw-pkgru3h8XOOQchfgOp_5Fo3b_dYpG0BYJ1NVKfdtO4H0edwCofbtn5Q9UN7iijPFusaJ_HMSDDQAX47NSHGxvZQa3N7iGYndkaJV7NDSF.' \\\n" +
                "  -H 'origin: https://www.goofish.com' \\\n" +
                "  -H 'priority: u=1, i' \\\n" +
                "  -H 'referer: https://www.goofish.com/' \\\n" +
                "  -H 'sec-ch-ua: \"Google Chrome\";v=\"135\", \"Not-A.Brand\";v=\"8\", \"Chromium\";v=\"135\"' \\\n" +
                "  -H 'sec-ch-ua-mobile: ?0' \\\n" +
                "  -H 'sec-ch-ua-platform: \"Windows\"' \\\n" +
                "  -H 'sec-fetch-dest: empty' \\\n" +
                "  -H 'sec-fetch-mode: cors' \\\n" +
                "  -H 'sec-fetch-site: same-site' \\\n" +
                "  -H 'user-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/135.0.0.0 Safari/537.36' \\\n" +
                "  --data-raw 'data=%7B%22pageNumber%22%3A1%2C%22keyword%22%3A%22%E5%A4%B4%E7%9B%94%E8%9B%8B%E9%BE%9F%22%2C%22fromFilter%22%3Atrue%2C%22rowsPerPage%22%3A30%2C%22sortValue%22%3A%22desc%22%2C%22sortField%22%3A%22create%22%2C%22customDistance%22%3A%22%22%2C%22gps%22%3A%22%22%2C%22propValueStr%22%3A%7B%22searchFilter%22%3A%22%22%7D%2C%22customGps%22%3A%22%22%2C%22searchReqFromPage%22%3A%22pcSearch%22%2C%22extraFilterValue%22%3A%22%7B%7D%22%2C%22userPositionJson%22%3A%22%7B%7D%22%7D'";

        Set<String> idSet = new HashSet<>();
        while (true){
            // 随机睡眠，10-20秒
            int sleepTime = (int) (Math.random() * 10000 + 10000);
            // 睡眠时间
            log.info("睡眠时间: {}秒", sleepTime / 1000);
            Thread.sleep(sleepTime);
            log.info("开始执行");
            try {
                extracted(apiString, email, idSet);
            } catch (Exception e) {
                log.error("执行失败", e);
            }
        }
    }

}
